home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8422 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.7 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is &Variable (declared as: char Variable[10])?
  5. Date: 3 Mar 1996 21:01:32 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hdtfcINN4l3@keats.ugrad.cs.ubc.ca>
  8. References: <4gqpa1$3h9@alcor.usc.edu> <4gtab6$acb@ceylon.gte.com> <4gvksnINNnug@anvil.ugrad.cs.ubc.ca> <TANMOY.96Feb29100937@qcd.lanl.gov>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <TANMOY.96Feb29100937@qcd.lanl.gov>,
  12. Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> wrote:
  13. >In article <4gvksnINNnug@anvil.ugrad.cs.ubc.ca>
  14. >c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  15. >
  16. ><snip>
  17. >KK: False. The _name_ 'myarray' is an array object. The _expression_ 'myarray'
  18. >KK: produces a pointer.
  19. >
  20. >except when it is the direct operand of the & operator or the direct
  21. >operand of the sizeof operator. (You say that later: but that is much
  22. >later :-).
  23.  
  24. Well, the operand of a sizeof operator can be an expression, or a parenthesized
  25. type name. If it is an expression, it is not evaluated, but only checked for
  26. those attributes which determine the size of the lvalue. Conceptually, the
  27. expression still has a value, albeit one which is thrown away. 
  28.  
  29. In the case of &, the operator does require the ``cast-expression''
  30. syntactic unit, but again, it is interested in something other than the
  31. straightforward value of the expression. The subject must be marked as an
  32. lvalue that meets certain criteria. For all I know, in the expression
  33.  
  34.     &myarray
  35.  
  36. where myarray is an array of char, the myrray constituent could still be
  37. treated as an expression that produces a pointer, a value that is ignored
  38. because some other attribute of the expression is interesting to the &
  39. operator.
  40.  
  41. By the same reasoning, if I have an integer 'i' initialized to 3, and write
  42.  
  43.     &i
  44.  
  45. the i constituent is still an expression whose value is 3. However, the &
  46. construct is interested in that i is an lvalue of a certain type and address,
  47. and that it has an address, and the (conceptually present) computational value
  48. is ignored.
  49.  
  50. It's always useful to think of expressions and other constructs as not
  51. computing only values, but also all kinds of other attributes, including type,
  52. l- versus r- value markers and so forth, any of which can be the item of
  53. interest to a dominating syntactic unit in favor of the value.
  54.  
  55. In saying what the expression 'myarray' is, I should have been more thorough by
  56. mentioning what other attributes it has, not just the principal computational
  57. pointer value. Thus, here is my second attempt:
  58.  
  59. myarray is an expression whose evaluation calls for the generation of a value,
  60. whose type is pointer to char and which points to the first element of myarray.
  61. However, the expression myrray also has other attributes. It is an lvalue which
  62. can be the subject of sizeof() and & operators, which are not interested in
  63. computing the pointer value,  but which look at the type and storage attributes
  64. of myarray itself. It is not a modifiable lvalue, hence it cannot be assigned
  65. to.
  66.  
  67. A compiler could represent this reality in the form of a parse tree, in which
  68. myarray would form a ``unary expression'' node. After type-checking and other
  69. phases, the node would contain attribute information which would indicate that
  70. it is an lvalue, and that it evaluates to a char * pointer type. Of course, the
  71. code to evaluate will not be created by the code generation phase since the &
  72. operator does not require the value attribute for anything.
  73.  
  74. The bottom line is that it's not necessary to view the subjects of & and sizeof
  75. as special cases; expressions are the same in the context of these operators as
  76. they are anywhere else, and can be seen as producing the same values.
  77. -- 
  78.  
  79.